<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('收款账号列表')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: s2ztree-css" />
    <th:block th:include="include :: switch-css" />

</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>归属码商：</label>
<!--                                <select name="userId" id="userId" class="form-control"-->
<!--                                        th:with="type=${@sysUser.selectUserListByType('ms')}">-->
<!--                                    <option value="">所有</option>-->
<!--                                    <option th:each="dict : ${type}" th:text="${dict.userName}"-->
<!--                                            th:value="${dict.userId}"></option>-->
<!--                                </select>-->
                                <select  name="userId" id="userId" class="form-control"></select>

                            </li>

                            <li>
                                <label>通道类型：</label>
                                <select name="channelType" id="channelType" class="form-control" th:with="type=${@dict.getType('channel_type')}" onchange="changeType()">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>通道编码：</label>
                                <select name="channel" id="channel"  class="form-control" >
                                    <option value="">所有</option>
                                </select>
                            </li>
                            <li>
                                <label>通道账号：</label>
                                <input type="text" name="channelAccount"/>
                            </li>
                            <li>
                                <label>是否禁用：</label>
                                <select name="channelDisabled"  class="form-control" th:with="type=${@dict.getType('yes_or_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否可用：</label>
                                <select name="available"  class="form-control" th:with="type=${@dict.getType('yes_or_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否在线：</label>
                                <select name="online"  class="form-control" th:with="type=${@dict.getType('yes_or_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>分组标签：</label>
                                <input type="text" class="form-control" id="groupName" name="groupName">
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:recipientInfo:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.copy()" shiro:hasPermission="business:recipientInfo:edit">
                    <i class="fa fa-plus"></i> 复制
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="business:recipientInfo:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:recipientInfo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:recipientInfo:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
     <th:block th:include="include :: s2ztree-js" />
     <th:block th:include="include :: switch-js" />
     <th:block th:include="include :: bootstrap-typeahead-js" />
     <script th:inline="javascript">
         var setting = {
             view : {
                 dblClickExpand : false,
                 expandAll: true  // 设置默认展开所有节点
             },
             data : {
                 simpleData : {
                     enable : true
                 }
             }
         };
         var userTreeurl = ctx + "system/user/userTreeData" ;
         var editFlag = [[${@permission.hasPermi('business:recipientInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('business:recipientInfo:remove')}]];
        var prefix = ctx + "business/recipientInfo";
        var typedata = [[${@dict.getType('channel_type')}]];
        var ysdata = [[${@dict.getType('yes_or_no')}]];
        var reslogindata = [[${@dict.getType('rec_login_type')}]];


        $(function() {
            getUserSelectTree();
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                copyUrl: prefix + "/copy/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "收款账号",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'userName',
                    title: '码商名称/分组',
                    formatter: function(value, row, index) {
                        return ('<span style="color: green;">'+row.userName+ '</span></br><span style="color: red;">' + (row.groupName== null ? '无分组' : row.groupName )+"</span>")
                    }
                },
                // {
                //     field: 'platformIs',
                //     title: '是否平台收款账号'
                // },
                {
                    field: 'channelType',
                    title: '通道类型',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(typedata, item.channelType);
                    }
                },
                {
                    field: 'channelName',
                    title: '通道名称'
                },

                {
                    field: 'channelAccount',
                    title: '通道账号'
                },
                    {
                        field: 'realName',
                        title: '账号别名'
                    },
                {
                    field: 'channelDisabled',
                    title: '通道状态',
                    // formatter: function(value, item, index) {
                    //     return $.table.selectDictLabel(ysdata, item.channelDisabled);
                    // }
                    formatter: function (value, row, index) {
                        let swState = row.channelDisabled == 0 ? true : false;
                        return '<input type="checkbox" name="isChannelDisabled" '+(swState ? "checked" : "")+' value="'+row.id+'"/>';
                        // return disablestatusTools(row);
                    }
                },
                // {
                //     field: 'cardId',
                //     title: '银卡ID'
                // },
                // {
                //     field: 'cardNo',
                //     title: '银行卡号'
                // },
                // {
                //     field: 'alipayCardid',
                //     title: '支付宝cardid'
                // },
                // {
                //     field: 'realName',
                //     title: '实名'
                // },
                // {
                //     field: 'serveMerId',
                //     title: '服务于指定用户'
                // },
                {
                    field: 'available',
                    title: '账号状态',
                    // formatter: function(value, item, index) {
                    //     return $.table.selectDictLabel(ysdata, item.available);
                    // }
                    formatter: function (value, row, index) {
                        let swState = row.available == 1 ? true : false;
                        return '<input type="checkbox" name="isAvailable" '+(swState ? "checked" : "")+' value="'+row.id+'"/>';
                        // return availablestatusTools(row);
                    }
                },
                {
                    field: 'online',
                    title: '在线状态',

                    formatter: function (value, row, index) {
                        return statusTools(row);
                    },
                },
                // {
                //     field: 'lastHeartbeat',
                //     title: '上一次心跳时间'
                // },
                // {
                //     field: 'needOnline',
                //     title: '是否需要客户端在线'
                // },
                // {
                //     field: 'accountJson',
                //     title: '收款账号信息'
                // },
                // {
                //     field: 'receiptQrcode',
                //     title: '收款二维码'
                // },
                // {
                //     field: 'imei',
                //     title: '手机序列号imei'
                // },
                // {
                //     field: 'deviceInfo',
                //     title: '设备信息'
                // },
                // {
                //     field: 'limitDayMoney',
                //     title: '每天最高收取金额'
                // },
                {
                    field: 'todayMoney',
                    title: '今天已收金额',
                    formatter: function (value, row, index) {
                        return (row.todayMoney == null ? '-' : row.todayMoney/100 + '元')
                    }
                },
                // {
                //     field: 'limitMaxMoney',
                //     title: '最高允许收款'
                // },
                {
                    field: 'totalMoney',
                    title: '总收取金额',
                    formatter: function (value, row, index) {
                        return (row.totalMoney == null ? '-' : row.totalMoney/100 + '元')
                    }
                },
                // {
                //     field: 'shopManager',
                //     title: '是否店长模式'
                // },
                // {
                //     field: 'shopNickname',
                //     title: '店长昵称'
                // },
                // {
                //     field: 'shopClerkAccount',
                //     title: '店员的账号'
                // },
                // {
                //     field: 'shopClerkOnline',
                //     title: '店员监控客户端是否在线'
                // },
                // {
                //     field: 'totalCount',
                //     title: '总的成功收款笔数'
                // },
                // {
                //     field: 'limitMaxCount',
                //     title: '限制总的成功收款笔数'
                // },
                {
                    field: 'todayCount',
                    title: '今日笔数'
                },
                // {
                //     field: 'limitDayCount',
                //     title: '限制今日成功收款笔数'
                // },
                {
                    field: 'supportAmount',
                    title: '二维码金额',
                    formatter: function (value, row, index) {
                        return (row.supportAmount == null ? '-' : row.supportAmount/100 + '元')
                    }
                },
                // {
                //     field: 'payJsKey',
                //     title: 'PAYJS秘钥'
                // },
                // {
                //     field: 'lastCreateBillTime',
                //     title: '最后产码时间'
                // },
                // {
                //     field: 'idCardName',
                //     title: '身份证姓名'
                // },
                // {
                //     field: 'idCardNo',
                //     title: '身份证号码'
                // },
                // {
                //     field: 'phoneNo',
                //     title: '手机号码'
                // },
                // {
                //     field: 'jdBuyerId',
                //     title: '京东买手号'
                // },
                // {
                //     field: 'cookie',
                //     title: '思语cookie'
                // },
                // {
                //     field: 'todayTmpMoney',
                //     title: '今日临时总收款'
                // },
                // {
                //     field: 'jdDfCityId',
                //     title: '京东电费缴费城市'
                // },
                // {
                //     field: 'jdDfUnitId',
                //     title: '电费缴费单位'
                // },
                // {
                //     field: 'jdDfBlance',
                //     title: '电费余额'
                // },
                {
                    field: 'onecePayLimit',
                    title: '单笔限额',
                    formatter: function (value, row, index) {
                        return (row.onecePayLimit == null ? '-' : row.onecePayLimit/100 + '元')
                    }
                },
                // {
                //     field: 'loginType',
                //     title: '登录类型'
                // },
                {
                    field: 'provinceName',
                    title: '归属省份'
                },
                {
                    field: 'cityName',
                    title: '归属城市'
                },
                // {
                //     field: 'bankName',
                //     title: ''
                // },
                // {
                //     field: 'disabledInfo',
                //     title: ''
                // },
                // {
                //     field: 'createUser',
                //     title: ''
                // },
                // {
                //     field: 'updateUser',
                //     title: ''
                // },
                // {
                //     field: 'weiShu',
                //     title: ''
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        if(row.channel.startsWith("isv_alipay") && row.channel!='isv_alipay_zft'){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="isvAuth(\'' + row.id + '\')"><i class="fa fa-edit"></i>授权</a> ');
                        }
                        var more = [];
                        more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='checkCk(" + row.id + ")'><i class='fa fa-key'></i>检查CK</a> ");
                        more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='testRep(" + row.id + ")'><i class='fa fa-check-square-o'></i>测试子账号</a> ");
                        actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                        return actions.join('');
                        return actions.join('');
                    }
                }],
                onLoadSuccess: function(){
                    //
                    $("[name='isChannelDisabled']").bootstrapSwitch({
                        onText: '启用',
                        offText: '禁用',
                        size : 'small'
                    }).on('switchChange.bootstrapSwitch', function (event, state){
                        //修改操作
                        $.operate.post(prefix + "/changeChannelDisabledStatus", { "id": event.currentTarget.value, "channelDisabled": state ? 0 : 1 });
                    });

                    $("[name='isAvailable']").bootstrapSwitch({
                        onText: '启用',
                        offText: '禁用',
                        size : 'small'
                    }).on('switchChange.bootstrapSwitch', function (event, state){
                        //修改操作
                        $.operate.post(prefix + "/changeAvailableStatus", { "id": event.currentTarget.value, "available": state ? 1 : 0 });
                    });
                }
            };
            $.table.init(options);

            $.get(prefix + "/getGroupName", function(data){
                $("#groupName").typeahead({
                    source: data.value
                });
            },'json');
        });

        function online(id,online,loginType){
            $.modal.confirm('确定要' + (online === "0"?'上线':'下线') + '该收款账号吗？', function() {
                if(online=="0"){
                    if(loginType === 'passwd' || loginType === 'ck'){
                        // layer.load(2);
                        // admin.req(getProjectUrl() + 'recipientInfo/changeStatus', JSON.stringify({id: obj.data.id, online: obj.data.online === 0?1:0}), function(res){
                        //     layer.msg(res.message, {icon: 1, time: 1000}, function () {
                        //         insTb.reload();
                        //     });
                        // }, 'post');
                        requrl=prefix+"/login/"+id;
                        // var config = {
                        //     url:requrl ,
                        //     type: "post",
                        //     dataType: "json",
                        //     beforeSend: function () {
                        //         $.modal.loading("正在处理中，请稍后...");
                        //         // $.modal.disable();
                        //     },
                        //     success: function(result) {
                        //         $.modal.closeLoading();
                        //         if (result.code == web_status.SUCCESS) {
                        //             $.modal.msgSuccess(result.msg);
                        //         }else{
                        //             $.modal.alertError(result.msg);
                        //         }
                        //     }
                        // };
                        // $.ajax(config)
                        $.operate.post(requrl, {});

                    }else if(loginType === 'passwdcode'){
                        // showPwdCodeModel(row);
                    }else if(loginType === 'sms'){
                        $.modal.openTab("验证码登录", prefix + "/smsLogin/"+id);
                        var options ={
                            title:'验证码登录',
                            width: "800",
                            height: "200",
                            url: prefix + "/smsLogin/"+id,
                            callBack: smsLogin
                        };
                        $.modal.openOptions (options);
                    }else{
                        // showSendSmsModel(row);
                    }
                }else{
                    $.operate.post(prefix + "/changeOnLineStatus", { "id": id, "online": 0 });
                }

            })
        }

         function smsLogin (index, layero){
             layero.find("iframe")[0].contentWindow.submitHandler();
         }
        function isvAuth(row){
            $.modal.open("授权", prefix + "/isvAuth/"+row.id);
        }
        function changeType(){
            if($("#channelType").val()==""){
                return;
            }
            requrl=ctx+"business/channel/getChannel/"+$("#channelType").val();
            var config = {
                url:requrl ,
                type: "post",
                dataType: "json",
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    // $.modal.disable();
                },
                success: function(result) {
                    $.modal.closeLoading();
                    if (result.code == web_status.SUCCESS) {
                        $("#channel").html("<option value=\"\">所有</option>");
                        $.each(result.data, function(key, val) {
                            var option1 = $("<option>").val(val.channel).text(val.channelDesc);
                            $("#channel").append(option1);
                            // form.render('select');
                        });
                    }else{
                        $.modal.alertError(result.msg);
                    }
                }
            };
            $.ajax(config)
        }

        function statusTools(row) {
            if(row.online==0){
                if(row.needOnline==1)
                    return '<span style="color: red;">已下线</span>【<a class=\"btn btn-success btn-xs\" href=\"javascript:void(0)\" onclick="online(\'' + row.id + '\',\'' + row.online + '\',\'' + row.loginType + '\')"><i class="fa fa-edit"></i>上线</a> 】';
                    // return '已下线<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="online(\'' + row. + '\')"></i> ';
            else
                    return '<p style="color: red;">已下线</p>';
            }else{
                if(row.needOnline==1)
                    // return '已上线<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="online(\'' + row + '\')"></i> ';

                return '<span style="color: green;">已上线</span>【<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="online(\'' + row.id + '\',\'' + row.online + '\',\'' + row.loginType + '\')"><i class="fa fa-edit"></i>下线</a> 】';
                else
                    return '<span style="color: green;">已上线</span>';
            }

        }
        function disablestatusTools(row) {
            if (row.channelDisabled == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="channelenable(\'' + row.id + '\')"></i><span style="color: red;">禁用</span> ';
            } else {
                return '<span style="color: green;">启用</span><i class=\"fa fa-toggle-on text-info fa-2x\" onclick="channeldisable(\'' + row.id + '\')"></i> ';
            }
        }

        function availablestatusTools(row) {
            if (row.available == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="availablenable(\'' + row.id + '\')"></i><span style="color: red;">禁用</span>';
            } else {
                return '<span style="color: green;">启用</span><i class=\"fa fa-toggle-on text-info fa-2x\" onclick="availabldisable(\'' + row.id + '\')"></i> ';
            }
        }

        function channelenable(userId) {
            $.operate.post(prefix + "/changeChannelDisabledStatus", { "id": userId, "channelDisabled": 0 });
        }

        /* 用户管理启用 */
        function channeldisable(userId) {
            $.operate.post(prefix + "/changeChannelDisabledStatus", { "id": userId, "channelDisabled": 1 });
        }


        function availabldisable(userId) {
            $.operate.post(prefix + "/changeAvailableStatus", { "id": userId, "available": 0 });
        }

        /* 用户管理启用 */
        function availablenable(userId) {
            $.operate.post(prefix + "/changeAvailableStatus", { "id": userId, "available": 1 });
        }

         function getUserSelectTree() {
             //查询条件
             var params = {
                 merchantType: "ms"
             };
             var config = {
                 url:userTreeurl ,
                 type: "post",
                 dataType: "json",
                 data: params,
                 beforeSend: function () {
                     $.modal.loading("正在处理中，请稍后...");
                     // $.modal.disable();
                 },
                 success: function(result) {
                     $.modal.closeLoading();
                     $('select[name=userId]').select2ztree({
                         textField : 'name',
                         titleField : 'name',
                         ztree : {
                             setting : $.extend(true, {
                                 treeId : 'userId'
                             }, setting),
                                 zNodes : result
                         }
                     });

                 }
             };
             $.ajax(config)
         }
         // function setGroup() {
         //     var rows = $.table.selectFirstColumns();
         //     if (rows.length == 0) {
         //         $.modal.alertWarning("请至少选择一条记录");
         //         return;
         //     }
         //     layer.prompt({
         //         formType: 0,
         //         title: '请输入分组名称',
         //     }, function (value, index, elem) {
         //         var reg = /^*$/;
         //         if (!reg.test(value)) {
         //             $.modal.msgError("请输入分组名称");
         //             return;
         //         }
         //         layer.close(index);
         //         var data = {"ids": rows.join(), groupName: value};
         //         var config = {
         //             url: prefix + "/setGroupName",
         //             type: "post",
         //             dataType: "json",
         //             data: data,
         //             beforeSend: function () {
         //                 // $.modal.loading("正在处理中，请稍后...");
         //                 // $.modal.disable();
         //             },
         //             success: function (result) {
         //                 if (result.code == web_status.SUCCESS) {
         //                     $.modal.msgSuccess(result.msg);
         //                 } else {
         //                     $.modal.msgError(result.msg);
         //                 }
         //                 $.modal.closeLoading();
         //             }
         //         };
         //         $.ajax(config)
         //     });
         // }
         function checkCk(id) {
             requrl=prefix+"/checkCK/"+id;
             var config = {
                 url:requrl ,
                 type: "post",
                 dataType: "json",
                 beforeSend: function () {
                     $.modal.loading("正在处理中，请稍后...");
                     // $.modal.disable();
                 },
                 success: function(result) {
                     $.modal.closeLoading();
                     if (result.code == web_status.SUCCESS) {
                         $.modal.msgSuccess(result.msg);
                     }else{
                         $.modal.alertError(result.msg);
                     }
                     $.table.refresh();
                 }
             };
             $.ajax(config)
         }
         function testRep(id) {
             layer.prompt({
                 formType: 0,
                 title: '请输入测试金额',
             }, function (value, index, elem) {
                 var reg = /^[0-9]+(\.[0-9]{1,2})?$/;
                 if (!reg.test(value)) {
                     $.modal.msgError("请输入正确的金额");
                     return;
                 }
                 layer.close(index);
                 var data = {"id": id, testMoney: value};
                 var config = {
                     url: prefix + "/testPay",
                     type: "post",
                     dataType: "json",
                     data: data,
                     beforeSend: function () {
                         $.modal.loading("正在处理中，请稍后...");
                         // $.modal.disable();
                     },
                     success: function (result) {
                         if (result.code == web_status.SUCCESS) {

                             window.open(result.msg,'_blank');

                         } else {
                             $.modal.alertError(result.msg);
                         }
                         $.modal.closeLoading();
                     }
                 };
                 $.ajax(config)
             });
         }
    </script>
</body>
</html>